import $ from '../../utils/ajax.js';
import util from '../../utils/util.js';
const app = getApp();
Page({
    data: {
        content: {},
        avatar: false,
    },
    onLoad(options) {
    },
    onShow(){
        this.getAccountInfoById();
    },
    getAccountInfoById() {
        $.p(app.wxApp.url + 'agentnew/getRoleInfoByToken', {}, app.onStrart, (res) => {
            this.setData({
                content: res.data
            })
            app.onShop();
        }, (res) => {
            util.showToast(res.data)
        })
    },
    onAvatar() {
        const _this = this;
        this.setData({
            avatar: true,
        })
        wx.chooseImage({
            count: 1,
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'],
            success(res) {
                $.u(app.wxApp.url + 'upload/uploadImage2', res.tempFilePaths[0], {
                    'xfjtk': wx.getStorageSync('xfjtk')
                }, app.onStrart, (res) => {
                    $.p(app.wxApp.url + 'agentNew/editRoleInfo', {
                        headPortrait: res.data
                    }, app.onStrart, (res) => {
                        util.showToast(res.data)
                        _this.getAccountInfoById();
                    }, (res) => {
                        util.showToast(res.data)
                    })
                }, (res) => {
                    util.showToast(res.data)
                })
            }
        })
    },
    omn(res) {
        const prime = res.currentTarget.dataset;
        if (typeof (this.time) === 'undefined' || (res.timeStamp - this.time > 1000)) {
            wx.navigateTo({
                url: './' + prime.path + '?name=' + prime.name + '&is=' + prime.is + '&type=' + prime.type + '&prime=' + prime.prime
            })
        }
        this.time = res.timeStamp;
    },
    edit(){
        app.quit();
    },
})